package com.mouseoverstudio.brekee.service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.mouseoverstudio.brekee.Brekee;
import com.mouseoverstudio.brekee.Command;
import com.mouseoverstudio.brekee.Service;

public class ListService extends Service {

	public static Command serve(String[] args) throws NoSuchMethodException,
			IllegalArgumentException, InvocationTargetException,
			IllegalAccessException {
		// Method method = Brekee.class.getMethod(commandName, (Class[]) null);
		// Command command = (Command) method.invoke((Object[]) null,
		// (Object[]) null);
		Method method;
		String arg = args[1];
		Command command = Brekee.list(arg);
		for (short i = 2; i < args.length; i++) {
			arg = args[i];
			method = command.getClass().getMethod(arg, (Class[]) null);
			command = (Command) method.invoke(command, (Object[]) null);
		}
		return command;
	}

}
